﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entity;
using AccessOperator;
using System.Data.OleDb;
using BussinessLib;

/// <summary>
/// OrderServiceManager 的摘要说明
/// </summary>
/// 
namespace OrderService
{
    public class OrderServiceManager
    {
        public OrderServiceManager()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        public int testUserInfo(string username, string password)
        {
            string strSql = "select * from [User] where [U_sName] like '";
            strSql += username + "' and [U_sPwd] like '";
            strSql += password + "'";

            try
            {
                string strPath = ConfigurationManager.ConnectionStrings["StrConn"].ToString();
                CAccessOperator dboperator = new CAccessOperator(strPath);

                //Execute the SQL if everything is well return true
                //else return false
                OleDbDataReader dr = dboperator.DbRead(strSql);
                int uId = 0;
                if (dr.Read())
                {
                    //Role = int.Parse(dr["U_nRole"].ToString());
                    uId = int.Parse(dr["U_nID"].ToString());
                }
                dboperator.CloseDb();
                return uId;

            }
            catch (Exception e)
            {
                return 0;
            }



        }
        public int SeatNum(int iAttriID, string iResId, string startTime)
        {
            string strSql;

            // strSql = "select   from orderRecord  "
            strSql = "select count(*)  from Seat where T_nAttributeID = " + iAttriID
                + "and T_sResID = '" + iResId+"'";
            DataTable m_DataTable2 = new DataTable();
            Helper m_DataAccess2 = new Helper();
            m_DataTable2 = m_DataAccess2.ExecuteDataTable(strSql);
            int allnumber = int.Parse(m_DataTable2.Rows[0][0].ToString());

            strSql = "select sum(ord_nTableNum)  from OrderRecord where ord_nSeatAttri = " + iAttriID
                + "and ord_sResID =' " + iResId + "' and ord_dtArrivalTime = #" + startTime+"#;";
            m_DataTable2 = m_DataAccess2.ExecuteDataTable(strSql);
            //strSql = "select count(*) from m_DataTable2";
            //m_DataTable2 = m_DataAccess2.ExecuteDataTable(strSql);
            int orderednumber = int.Parse(m_DataTable2.Rows[0][0].ToString());



            int number = allnumber - orderednumber;
            return number;
        }
        public void createOrder(Order record, string username, string restaId, string startTime, int category, int numbers)
        {



            record.ArrivalTime = DateTime.Parse(startTime);
            record.BookTime = DateTime.Now;
            record.TableNum = numbers;
            //record.TableID = int.Parse(Request.QueryString[0]);

            record.TableType = category;

            //record.Description = this.txt_Memo.Text;
            record.UserID = username;


        }
    }

}
